local rier = fk.CreateSkill {
  name = "th_rier",
  max_branches_use_time = {
    ["red"] = {
      [Player.HistoryTurn] = 1
    },
    ["black"] = {
      [Player.HistoryTurn] = 1
    },
  }
}

rier:addEffect(fk.TargetConfirmed, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(rier.name) and not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local canDiscard = table.filter(target:getCardIds("he"), function(id) return not player:prohibitDiscard(id) end)
    if #canDiscard == 0 then
      return false
    end
    local prompt = "#th_rier-invoke"
    local banned
    if not rier:withinBranchTimesLimit(player, "red") then
      prompt = "#th_rier-black"
      banned = Card.Red
    elseif not rier:withinBranchTimesLimit(player, "black") then
      prompt = "#th_rier-red"
      banned = Card.Black
    end
    local _, dat = room:askToUseActiveSkill(player, {
      skill_name = "#th_rier_choose",
      prompt = prompt,
      extra_data = {
        skillName = rier.name,
        banned = banned
      }
      })
    if dat then
      local c = Fk:getCardById(dat.cards[1])
      event:setCostData(self, { cards = dat.cards, history_branch = c:getColorString()})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local dat = event:getCostData(self)
    local c = Fk:getCardById(dat.cards[1])
    room:throwCard(dat.cards, rier.name, player, player)
    -- room:addTableMark(player, "th_rier-turn", c:getColorString())
    if c.color == Card.Red then
      player:drawCards(2, rier.name)
    else
      room:askToGuanxing(player, {
        cards = room:getNCards(4),
        bottom_limit = {0, 0},
      })
    end
  end,
}, { check_skill_limit = true })

Fk:loadTranslationTable{
  ["th_rier"] = "日珥",
  [":th_rier"] = "每回合各限一次，当你成为使用牌的目标后，你可以：1.弃置任意张红色牌然后摸两张牌；2.弃置任意张黑色的牌然后观看牌堆顶四张牌并调整顺序。",

  ["#th_rier-invoke"] = "日珥：你可以弃置任意张红色牌然后摸两张牌，或弃置任意张黑色的牌然后观看牌堆顶四张牌并调整顺序",
  ["#th_rier-red"] = "日珥：你可以弃置任意张红色牌然后摸两张牌",
  ["#th_rier-black"] = "日珥：你可以弃置任意张黑色的牌然后观看牌堆顶四张牌并调整顺序",
}

return rier